package demo.dcs.vo;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author mandy.hu
 * 
 */
public class SampleStatModel implements Serializable {

	private static final long serialVersionUID = -3212103442431669566L;

	private long timestamp;

	private Map<String, SampleStatResult> sampleMap = new ConcurrentHashMap<String, SampleStatResult>();

	private int maxCached = 102400;

	private volatile boolean isFull = false;

	/**
	 * @return the timestamp
	 */
	public long getTimestamp() {

		return timestamp;
	}

	/**
	 * @param timestamp
	 *            the timestamp to set
	 */
	public void setTimestamp(long timestamp) {

		this.timestamp = timestamp;
	}

	/**
	 * @return the sampleMap
	 */
	public Map<String, SampleStatResult> getSampleMap() {

		return sampleMap;
	}

	/**
	 * @param sampleMap
	 *            the sampleMap to set
	 */
	public void setSampleMap(Map<String, SampleStatResult> sampleMap) {

		this.sampleMap = sampleMap;
	}

	/**
	 * 
	 */
	public void rest() {

		sampleMap.clear();

	}

	/**
	 * @return the isFull
	 */
	public boolean isFull() {

		return isFull;
	}

	/**
	 * @param isFull
	 *            the isFull to set
	 */
	public void setFull(boolean isFull) {

		this.isFull = isFull;
	}

	private class LRULinkHashMap<K, V> extends LinkedHashMap<K, V> {


		private static final long serialVersionUID = -49662338547994814L;

		public LRULinkHashMap(int initialCapacity, float loadFactor, boolean accessOrder) {

			super(initialCapacity, loadFactor, accessOrder);

		}

		@Override
		protected boolean removeEldestEntry(Entry<K, V> eldest) {

			if (this.size() > maxCached) {
				isFull = true;
				return true;
			}

			return false;
		}

	}

}
